import { getUrlShopId } from "/utils/commonMethod"
import { showToast } from "/utils/common";
import request from "/utils/request"
Page({
  data: {},
  onLoad() { },
  onSubmit(e) {
    let obj = e.detail.value
    obj.shopId = getUrlShopId(obj.shopId)
    if (!obj.name) {
      showToast({
        msg: "商户名称不能为空",
      })
      return
    }
    if (!obj.categoryName) {
      showToast({
        msg: "商户类别不能为空",
      })
      return
    }
    if (obj.shopId) { //门店id不能为空   
      dd.showLoading({
        content: "加载中..."
      })
      request({
        headers: {
          "Content-Type": "application/json;charset=UTF-8"
        },
        url: "/api/crm/shop/createToBeExecutedShop",
        method: "post",
        data: obj
      }).then(res => {
        if (res.success) {
          dd.hideLoading()
          dd.redirectTo({
            url: `/pages/privateCustomers/add-private-sea-success/add-private-sea-success?selectedShopNum=1&allShopNum=1`
          })
        }
      }).catch(() => {
        dd.navigateBack();
      }).finally(() => {
        dd.hideLoading()
      })
    } else {
      showToast({
        msg: "门店id不符合规则"
      })
    }
  }
});
